package com.dv.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dv.common.core.domain.entity.SysUser;
import com.dv.common.utils.DateUtils;
import com.dv.driverless.domain.EquipmentRadar;
import com.dv.driverless.service.IEquipmentRadarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.poi.ExcelUtil;
import com.dv.common.core.page.TableDataInfo;

/**
 * 雷达信息Controller
 *
 * @author ruoyi
 * @date 2023-04-02
 */
@Api("雷达信息")
@RestController
@RequestMapping("/equipment/radar")
public class EquipmentRadarController extends BaseController
{
    @Autowired
    private IEquipmentRadarService equipmentRadarService;

    /**
     * 查询雷达信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:radar:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentRadar equipmentRadar)
    {
        startPage();
        List<EquipmentRadar> list = equipmentRadarService.selectEquipmentRadarList(equipmentRadar);
        return getDataTable(list);
    }

    /**
     * 导出雷达信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:radar:export')")
    @Log(title = "雷达信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentRadar equipmentRadar)
    {
        List<EquipmentRadar> list = equipmentRadarService.selectEquipmentRadarList(equipmentRadar);
        ExcelUtil<EquipmentRadar> util = new ExcelUtil<EquipmentRadar>(EquipmentRadar.class);
        util.exportExcel(response, list, "雷达信息数据");
    }

    /**
     * 获取雷达信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:radar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentRadarService.selectEquipmentRadarById(id));
    }

    /**
     * 新增雷达信息
     */
    @PreAuthorize("@ss.hasPermi('system:radar:add')")
    @Log(title = "雷达信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentRadar equipmentRadar)
    {
        equipmentRadar.setCreateDate(DateUtils.getNowDate());
        return toAjax(equipmentRadarService.insertEquipmentRadar(equipmentRadar));
    }

    /**
     * 修改雷达信息
     */
    @PreAuthorize("@ss.hasPermi('system:radar:edit')")
    @Log(title = "雷达信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentRadar equipmentRadar)
    {
        return toAjax(equipmentRadarService.updateEquipmentRadar(equipmentRadar));
    }

    /**
     * 删除雷达信息
     */
    @PreAuthorize("@ss.hasPermi('system:radar:remove')")
    @Log(title = "雷达信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentRadarService.deleteEquipmentRadarByIds(ids));
    }

    /**
     * 雷达状态修改
     * @param equipmentRadar
     * @return
     */
    @ApiOperation("radar")
    @Log(title = "雷达信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody EquipmentRadar equipmentRadar)
    {
        equipmentRadar.setUpdateBy(getUsername());
        return toAjax(equipmentRadarService.updateUserStatus(equipmentRadar));
    }

}
